using System;
using System.Linq;
using System.Text;
using DevExpress.ExpressApp;
using DevExpress.Data.Filtering;
using System.Collections.Generic;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Utils;
using DevExpress.ExpressApp.Layout;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Templates;
using DevExpress.Persistent.Validation;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.ExpressApp.Model.NodeGenerators;
using ActivityLibrary1;
using System.Diagnostics;
using DanielOnHyperion5.Module.BusinessObjects;
using DevExpress.ExpressApp.DC;

namespace DanielOnHyperion5.Module.Controllers
{
    // For more typical usage scenarios, be sure to check out http://documentation.devexpress.com/#Xaf/clsDevExpressExpressAppViewControllertopic.
    public partial class RunTestPlan : ViewController
    {
        public RunTestPlan()
        {
            InitializeComponent();
            RegisterActions(components);
            // Target required Views (via the TargetXXX properties) and create their Actions.
        }
        protected override void OnActivated()
        {
            base.OnActivated();
            // Perform various tasks depending on the target View.
        }
        protected override void OnViewControlsCreated()
        {
            base.OnViewControlsCreated();
            // Access and customize the target View control.
        }
        protected override void OnDeactivated()
        {
            // Unsubscribe from previously subscribed events and release other references and resources.
            base.OnDeactivated();
        }

        private void simpleAction1_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            //string myFavoritesPath =
            //    Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
            //int id = (int)HFMCONSTANTSLib.tagHFMDIMENSIONS.DIMENSIONENTITY;
            //Process.Start("cscript.exe", String.Format("{0} {1} {2} {3} {4} {5} {6}", "test.vbs", ""));      
            HFMServer Server = ((TestPlan)e.CurrentObject).HFMServer;
            if (Server.XCode != Server.NameXCode)
            {
                return;
            }

            foreach (TestItem item in ((TestPlan)e.CurrentObject).TestItems)
            {
                //ProcessStartInfo StartInfo = new ProcessStartInfo()
                //  {
                //      CreateNoWindow = true,
                //      WindowStyle = ProcessWindowStyle.Hidden,
                //      FileName = "ping.exe",
                //      Arguments = "10.10.10.1"
                //  };
                //Process.Start(StartInfo); 
                Process.Start("wscript.exe", String.Format(" {0} {1} {2} {3} {4} {5} {6} {7} {8}", "test.vbs", Server.Cluster, Server.Application, item.UserName, item.Password, item.Scenario, item.Year, item.Period, item.Entity));            
            }
        }
    }
}
